<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="计划名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入计划名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">
          <el-option v-for="dict in typeOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="计划月份" prop="planDate">
        <el-date-picker :editable="false" v-model="planDate" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="monthrange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="完成状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择完成状态" clearable size="small">
          <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['produce:plan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['produce:plan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['produce:plan:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['produce:plan:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['produce:plan:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-plus" size="mini"
          @click="dialogTableVisible = true">追加</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleDelete"
          v-hasPermi="['produce:plan:remove']"
          >批量刪除</el-button
        >
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange" max-height="550">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <!--<el-table-column label="计划编码" align="center" prop="code" />-->
      <el-table-column label="计划名称" align="center" prop="name" minWidth="130px" />
      <el-table-column label="所属基地" align="center" prop="deptName" />
      <el-table-column label="类型" align="center" prop="type" :formatter="typeFormat" />
      <el-table-column label="计划月份" align="center" prop="planDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planDate, "{y}/{m}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进度" align="center" prop="progress" />
      <el-table-column label="计划产量-标准箱" align="center" prop="totalPlanNumBox" />
      <!--<el-table-column label="工厂id" align="center" prop="deptId" />-->
      <el-table-column label="任务完成状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="耗材量" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="useHandleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-hasPermi="['produce:plan:view']">查看</el-button>
          <!-- <el-button
            v-if="scope.row.status == '1'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleFinish(scope.row)"
            v-hasPermi="['produce:plan:finish']"
            >直接完成</el-button
          >-->
          <el-button v-if="scope.row.progress.replace('%','') == 0" size="mini" type="text" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['produce:plan:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改生产计划对话框 -->
    <el-dialog v-myFullscreen :title="title" :visible.sync="open" width="700px" append-to-body v-myDialogDrag>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入计划名称" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型" prop="type">
              <el-select v-model="form.type" placeholder="请选择类型" :disabled="openDisabled">
                <el-option v-for="dict in typeOptions" :key="dict.dictValue" :label="dict.dictLabel"
                  :value="dict.dictValue"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划月份" prop="planDate">
              <el-date-picker :editable="false" clearable size="small" v-model="form.planDate" type="date"
                value-format="yyyy-MM-dd" placeholder="选择计划月份" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="进度" prop="progress">
              <el-input v-model="form.progress" placeholder="请输入进度" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 耗材量弹窗 -->
    <el-dialog v-myFullscreen :title="title" :visible.sync="open2" width="700px" append-to-body v-myDialogDrag>
      <!--<el-form :model="queryParams2" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="计划id" prop="planId">
          <el-input
            v-model="queryParams2.planId"
            placeholder="请输入计划id"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="详情id" prop="planDetailId">
          <el-input
            v-model="queryParams2.planDetailId"
            placeholder="请输入详情id"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>-->

      <!-- <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['produce:useDetail:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['produce:useDetail:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['produce:useDetail:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['produce:useDetail:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList2"></right-toolbar>
      </el-row>-->

      <el-table v-loading="loading2" :data="useDetailList" @selection-change="handleSelectionChange">
        <!--<el-table-column type="selection" width="55" align="center" />-->
        <!-- <el-table-column label="主键id" align="center" prop="id" />-->
        <el-table-column label="物料编码" align="center" prop="code" />
        <el-table-column label="物料名称" align="center" prop="name" />
        <el-table-column label="单位" align="center" prop="unit" />
        <el-table-column label="耗材量" align="center" prop="preUseNum" />
        <el-table-column label="剩余计划耗材量" align="center" prop="lastUseNum" />
        <el-table-column label="当前库存量" align="center" prop="stockNum" />
        <el-table-column label="当前差值" align="center" prop="needNumStr" />
      </el-table>

      <pagination v-show="total2 > 0" :total="total2" :page.sync="queryParams2.pageNum"
        :limit.sync="queryParams2.pageSize" @pagination="getList2" />

      <!--<div slot="footer" class="dialog-footer"  v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>-->
    </el-dialog>

    <!-- 计划导入对话框 -->
    <el-dialog v-myFullscreen :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <!--<el-form-item label="计划月份" prop="planDate">-->
      <el-date-picker clearable size="small" style="margin-bottom: 20px" v-model="pDate" type="month"
        value-format="yyyy-MM-dd" placeholder="选择计划月份">
      </el-date-picker>

      <!--</el-form-item>-->
      <el-upload :data="{'pDate': pDate}" ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />
          <el-link type="info" style="font-size: 12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--追加计划弹窗-->
    <el-dialog fullscreen title="追加" :visible.sync="dialogTableVisible" width="1100px">
      <el-form ref="form2" :model="form2" :rules="rules" label-width="86px">
        <el-row>
          <el-col :span="7">
            <el-form-item label="计划名称" prop="name">
              <el-input v-model="form2.name" placeholder="请输入计划名称" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="计划月份" prop="planDate">
              <el-date-picker :editable="false" clearable v-model="form2.planDate" type="month"
                value-format="yyyy-MM-dd" placeholder="选择计划月份">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="目标基地" prop="deptId">
              <!-- <el-input
                  v-model="form2.name"
                  placeholder="请选择目标基地"
                  style="width: 200px"
                />-->
              <el-select v-model="form2.deptId" placeholder="请选择目标基地">
                <el-option v-for="dict in factoryListOptions" :key="dict.deptId" :label="dict.name"
                  :value="dict.deptId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="5">
            <el-form-item label="类型" prop="type">
              <div>追加</div>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="状态" prop="status">
              <div>进行中</div>
            </el-form-item>
          </el-col>-->
        </el-row>
      </el-form>
      <el-button type="text" @click="add()" style="margin:20px 0 10px 0;">添加产品 </el-button>
      <el-table :data="list">
        <el-table-column label="序号" type="index" width="55" align="center"></el-table-column>
        <el-table-column label="产成品名称" min-width="200" align="center" prop="name">
          <template slot-scope="scope">
            <Dialog @dialogChange="dialogChange($event, scope)" :echoValue="scope.row.name" parameter="rows" value="id"
              label="name" :multiple="false" search="name/code" url="/basic/productInfo/listSelect"
              :column="['产成品编号/code', '产成品名称/name']" :axiosData="{ typeCode: ccpType }" placeholder="请选择内容" />
          </template>
        </el-table-column>
        <el-table-column label="产成品编号" align="center" prop="code">
          <template slot-scope="scope">
            <el-input v-model="scope.row.code" placeholder="产成品编号" :readonly="true" />
          </template>
        </el-table-column>
        <el-table-column label="销售计划" align="center" prop="name">
          <template slot-scope="scope">
            <el-input v-model="scope.row.salesPlanNum" placeholder="请输入销售计划量" :readonly="false" />
          </template>
        </el-table-column>
        <el-table-column label="单位" align="center" prop="code">
          <template slot-scope="scope">
            <el-input v-model="scope.row.unit" placeholder="单位" :readonly="true" />
          </template>
        </el-table-column>
        <el-table-column label="生产计划" align="center" prop="name">
          <template slot-scope="scope">
            <el-input v-model="scope.row.producePlanNum" placeholder="请输入生产计划量" :readonly="false" type="number"
              oninput="if(value<1)value=''" />
          </template>
        </el-table-column>
        <el-table-column label="库存" align="center" prop="name">
          <template slot-scope="scope">
            <el-input v-model="scope.row.stockCount" placeholder="请输入库存" :readonly="false" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="del(scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAddPlan">保 存</el-button>
        <el-button @click="restForm2">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    listPlan,
    getPlan,
    delPlan,
    addPlan,
    updatePlan,
    listUseDetail,
    addOhterPlan,
    uploadPlan,
    getFactoryList,
    finishPlan,
  } from "@/api/produce/plan/plan";
  import { getToken } from "@/utils/auth";

  export default {
    name: "Plan",
    data() {
      return {
        //弹窗是否禁止编辑
        openDisabled: true,
        // 遮罩层
        loading: true,
        loading2: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        ccpType: null,
        // 总条数
        total: 0,
        total2: 0,
        // 生产计划表格数据
        planList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 耗材量弹窗
        open2: false,
        // 类型字典
        typeOptions: [],
        // 任务完成状态字典
        statusOptions: [],
        factoryListOptions: [],
        // 计划导入参数
        upload: {
          // 是否显示弹出层（计划导入）
          open: false,
          // 弹出层标题（计划导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/produce/plan/import",
        },
        planDate: [],
        myDate: {},
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 50,
          name: null,
          type: null,
          planDateStrat: null,
          planDateEnd: null,
          status: null,
        },
        queryParams2: {
          pageNum: 1,
          pageSize: 10,
          planId: null,
          planDetailId: null,
        },
        // 表单参数
        form: {},
        form2: {},
        pDate: "",
        // 表单校验
        rules: {
          name: { validator: this.$rules.required("计划名称") },
          planDate: { validator: this.$rules.required("计划月份") },
          deptId: { validator: this.$rules.required("目标基地") },
        },
        list: [], //数据列表
        useDetailList: [],
        dialogTableVisible: false, //弹窗是否隐藏
      };
    },
    created() {
      this.getList();
      this.getDicts("plan_type").then((response) => {
        this.typeOptions = response.data;
      });
      this.getDicts("plan_status").then((response) => {
        this.statusOptions = response.data;
      });
      this.getConfigKey("ccp_type").then((response) => {
        this.ccpType = response.msg;
      });
      this.getFactoryList();
    },
    methods: {
      /** 查询生产计划列表 */
      getList() {
        this.loading = true;
        listPlan(this.queryParams).then((response) => {
          this.planList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getFactoryList() {
        getFactoryList().then((response) => {
          this.factoryListOptions = response.data;
        });
      },

      getList2() {
        this.loading2 = true;
        listUseDetail(this.queryParams2).then((response) => {
          this.useDetailList = response.rows;
          this.total2 = response.total;
          this.loading2 = false;
        }).catch(() => {
          this.useDetailList = []
          this.loading2 = false;
        });
      },
      // 类型字典翻译
      typeFormat(row, column) {
        return this.selectDictLabel(this.typeOptions, row.type);
      },
      // 任务完成状态字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        /*this.form = {
          id: null,
          code: null,
          name: null,
          type: null,
          // planDate: [],
          progress: null,
          deptId: null,
          status: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null,
          remark: null,
        };*/
        this.resetForm("form");
        this.planDate = [];
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        if (this.planDate && this.planDate.length > 0) {
          this.queryParams.planDateStart = this.planDate[0];
          this.queryParams.planDateEnd = this.planDate[1];
        }
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.planDate = [];
        this.queryParams.planDateStart = null;
        this.queryParams.planDateEnd = null;
        this.handleQuery();
      },

      /** 搜索按钮操作 */
      handleQuery2() {
        this.queryParams2.pageNum = 1;
        this.getList2();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.openDisabled = false;
        this.open = true;
        this.title = "添加生产计划";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.openDisabled = false;
        const id = row.id || this.ids;
        getPlan(id).then((response) => {
          this.form = response.data;
          this.open = true;
          this.title = "修改生产计划";
        });
      },
      /** 查看按钮 */
      handleView(row) {
        this.$router.push({
          path: "/produce/plan/planDetail",
          query: {
            planId: row.id,
            name: row.name,
            month: row.planDate,
            status: row.status,
            type: row.type,
          },
        });
      },

      useHandleView(row) {
        this.queryParams2.planId = row.id;
        this.open2 = true;
        this.title = "查看耗材";
        // });
        this.handleQuery2();
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            if (this.form.id != null) {
              updatePlan(this.form).then((response) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              const rLoading = this.openLoading();
              addPlan(this.form)
                .then((response) => {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  rLoading.close();
                  this.getList();
                })
                .catch((error) => {
                  rLoading.close();
                });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        if (ids.length > 0 || row.id) {
          this.$confirm(
            '是否确认删除生产计划编号为"' + ids + '"的数据项?',
            "警告",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          )
            .then(function () {
              return delPlan(ids);
            })
            .then(() => {
              this.getList();
              this.msgSuccess("删除成功");
            })
            .catch(() => { });
        }
      },

      handleFinish(row) {
        const ids = row.id || this.ids;
        if (ids.length > 0 || row.id) {
          this.$confirm(
            '是否确认直接完成生产计划编号为"' + ids + '"的数据项?',
            "警告",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          )
            .then(function () {
              /*alert("快速完成");*/
              return finishPlan(ids);
            })
            .then(() => {
              this.getList();
              this.msgSuccess("操作成功");
            })
            .catch(() => { });
        }
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "produce/plan/export",
          {
            ...this.queryParams,
          },
          "生产计划" + this.parseTime(new Date()) + ".xlsx"
        );
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "计划导入";
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        this.download(
          "produce/plan/importTemplate",
          {
            ...this.queryParams,
          },
          `生产计划导入模板.xlsx`
        );
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        if (!this.pDate) {
          this.$message({
            message: "请选择时间",
            type: "warning",
          });
          return;
        }
        this.$refs.upload.submit();
      },

      // 追加框事件---------------
      del(index) {
        //删除
        this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.list.splice(index, 1);
          })
          .catch(() => { });
      },
      dialogChange(event, scope) {
        //选择后续操作
        if (event.options instanceof Array == true) {
          this.list.splice(scope.$index, 1, ...event.options);
        } else {
          this.list[scope.$index].name = event.options.name;
          this.list[scope.$index].code = event.options.code;
          this.list[scope.$index].unit = event.options.unit;
        }
        this.list.push({});
        this.list.pop();
      },
      add() {
        //添加
        this.list.push({});
      },
      submitAddPlan() {
        // this.dialogTableVisible = false;
        // alert(111111)
        var planName = this.form2.name;
        var planDate = this.form2.planDate;
        var deptId = this.form2.deptId;
        var temp = 0;
        this.$refs["form2"].validate((valid) => {
          if (valid) {
            if (this.list.length > 0) {
              for (let i in this.list) {
                if (
                  this.list[i].salesPlanNum &&
                  this.list[i].producePlanNum &&
                  this.list[i].stockCount &&
                  this.list[i].name
                ) {
                  temp++;
                } else {
                  /*alert(i+1+'未显示');*/
                  this.$message.closeAll();
                  this.$message({
                    message: i + 1 + "行信息不全",
                    type: "warning",
                  });
                }
              }
              if (temp == this.list.length) {
                addOhterPlan({
                  productPlanDetailList: this.list,
                  name: planName,
                  planDate: planDate,
                  deptId: deptId,
                }).then((response) => {
                  this.msgSuccess("计划追加成功");
                  this.getList();
                  /*this.resetForm("form2");*/
                  this.restForm2();
                });
              }
            } else {
              this.$message.closeAll();
              this.$message({
                message: "请先添加产成品！",
                type: "warning",
              });
            }
          }
        });
      },
      restForm2() {
        this.list = [];
        this.form2.name = null;
        this.form2.planDate = null;
        this.dialogTableVisible = false;
      },
    },
  };
</script>